package com.vr.xuecheng.feign.fallback;

import com.vr.xuecheng.feign.client.MediaClient;
import com.vr.xuecheng.feign.response.Result;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author hzh
 * @date 2025/03/21
 * 熔断后降级的回调
 */
@Component
public class MediaFallbackFactory implements FallbackFactory<MediaClient> {
    @Override
    public MediaClient create(Throwable cause) {
        return new MediaClient() {
            @Override
            public Result<String> upload(MultipartFile file, String objectName) {
                return Result.error("调用媒资服务上传失败", cause.getMessage());
            }

            @Override
            public Result<String> getFilePathById(String mediaId) {
                // 返回默认值或抛出异常
                return Result.error("调用媒资服务获取文件路径失败", cause.getMessage());
            }
        };
    }
}
